package com.epfresh.utils;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.text.TextPaint;
import android.widget.TextView;

import com.epfresh.api.utils.LocalDisplay;
import com.epfresh.bean.HomeCommTag;

/**
 * @author wangzhanghuan
 * @version 1.0
 * @date create 17-2-21
 * @Description
 */

public class CommonUtils {

    public static void intoPhone(Context context, String phone) {
        if (context == null)
            return;
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));//调出来拨打页面；
        context.startActivity(intent);
    }

    public static float getTextWidth(Context Context, String text, float textSize){
        TextPaint paint = new TextPaint();
        float scaledDensity = Context.getResources().getDisplayMetrics().scaledDensity;
        paint.setTextSize(scaledDensity * textSize);
        return paint.measureText(text);
    }

    public static void updateBg(TextView tv, HomeCommTag homeCommTag){
        String color = homeCommTag.getColor();
        int strokeWidth = LocalDisplay.dp2px(0.75f);     // 边框宽度
        float roundRadius = LocalDisplay.dp2px(8f);// 圆角半径
//                int strokeColor = Color.parseColor("#FFFF0000");//边框颜色
        int strokeColor = Color.parseColor(color);//边框颜色
        int fillColor = Color.parseColor("#ffffffff"); //内部填充颜色
        GradientDrawable gd = new GradientDrawable();//创建drawable
        gd.setColor(fillColor);
        gd.setCornerRadius(roundRadius);
        gd.setStroke(strokeWidth, strokeColor);
        gd.setGradientType(GradientDrawable.LINEAR_GRADIENT);

        tv.setBackgroundDrawable(gd);
        tv.setTextColor(strokeColor);
    }

}
